home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.001 / crossfir~ / eutl / xmalloc / xmalloc.c < prev    next >
C/C++ Source or Header  |  1994-01-14  |  2KB  |  79 lines

  1. #include "xmalloc.h"
  2. #include <malloc.h>
  3. #include "libc.h"
  4.  
  5. /*
  6.  *   eutl - A collection of useful libraries
  7.  *   xmalloc - malloc wrappers which use the errlib routines so clients
  8.  *             can assume the mallocs succeeded.
  9.  *
  10.  *   (c) Copyright 1993 Eric Anderson 
  11.  *
  12.  * My thanks to Geoffrey Collyer and Henry Spencer for providing the basis
  13.  * for this copyright.
  14.  *
  15.  * Permission is granted to anyone to use this software for any purpose on
  16.  * any computer system, and to alter it and redistribute it freely, subject
  17.  * to the following restrictions:
  18.  *
  19.  * 1. The authors are not responsible for the consequences of use of this
  20.  *    software, no matter how awful, even if they arise from flaws in it.
  21.  *
  22.  * 2. The origin of this software must not be misrepresented, either by
  23.  *    explicit claim or by omission.  Since few users ever read sources,
  24.  *    credits must appear in the documentation.
  25.  *
  26.  * 3. Altered versions must be plainly marked as such, and must not be
  27.  *    misrepresented as being the original software.  Since few users
  28.  *    ever read sources, credits must appear in the documentation.
  29.  *
  30.  * 4. This notice may not be removed or altered.
  31.  */
  32.  
  33. static ErrorFunction erf = AbortErrorFunction;
  34. char *xmalloc_packagever = "XMalloc 1.0";
  35. char *xmalloc_Enomem = "Out of Memory";
  36.  
  37. void xmalloc_seterf(ErrorFunction nerf)
  38. {
  39.   erf = nerf;
  40. }
  41.  
  42. void *xmalloc(unsigned long size)
  43. {
  44.   void *ret;
  45.  
  46.   if (size==0)
  47.     size=1;
  48.   ret = malloc(size);
  49.   if (ret==NULL) {
  50.     erf(xmalloc_packagever,xmalloc_Enomem,
  51.     "Unable to allocate %d bytes\n",size);
  52.   }
  53.   return ret;
  54. }
  55.  
  56. void *xrealloc(void *old,unsigned long size)
  57. {
  58.   void *ret;
  59.  
  60.   if (old == NULL)
  61.     return xmalloc(size);
  62.   ret = realloc(old,size);
  63.   if (ret == NULL) 
  64.     erf(xmalloc_packagever,xmalloc_Enomem,
  65.     "Unable to reallocate to %d bytes\n",size);
  66.   return ret;
  67. }
  68.  
  69. void *xbzmalloc(unsigned long size)
  70. {
  71.   void *ret;
  72.   
  73.   ret = xmalloc(size);
  74.   bzero(ret,size);
  75.   return ret;
  76. }
  77.  
  78.     
  79.